<?php

class vista 
{
    public $html = "";
    public $contenido = "";
    public $post = "";
    public $title = "";
    public $mensaje = "";
    public $redirect = "";
    
    public $empleadoS = null;

    public function __construct($archivo) 
    {
        if(isset($_SESSION['eid']))
            $this->empleadoS = new duenoDatos($_SESSION['eid']);
        
        $this->getHtml($archivo);
        return $this;
    }
    public function show()
    {
        return $this->html;
    }
    
    public function getHtml($archivo)
    {
        $file = fopen($archivo,"r");
    
        while(!feof($file))
        {
            $this->html = $this->html . fread($file,100); 
        }
        
    }

    public function preShow()
    {
        $this->prepararContenido();
        
        if($_POST)
        {
            $this->reqPost();
        }
        if($_GET)
        {
            $this->reqPost();
        }
        return $this->show();
    }

    public function prepararContenido()
    {
        $meses = array("","Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
        
        $dia = date("d");
        $mes = date("n");
        $anyo = date("Y");
        
        $mes = $meses[$mes];
        
        $fecha = $dia . " de " . $mes . " de " . $anyo;
        
        $this->html = str_replace("::fecha::", $fecha, $this->html);

        $this->html = str_replace("::post::",$this->post,$this->html);

        $this->html = str_replace("::titulo::",$this->title,$this->html);
        
        foreach($_GET as $key => $value)
        {
            if(!isset($_POST[$key]))
                $_POST[$key] = $value;
        }
        
    }   
    
    public function reqPost()
    {
        if($this->mensaje != "")
            $this->html = str_replace("::mensaje::", $this->mensaje, $this->html);
        if($this->redirect != "")
            $this->html = str_replace("::redirect::", $this->redirect, $this->html);
    }
  
 

}

